package com.kma.summer2012.client.view.authorization;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.*;
import com.kma.summer2012.client.presenters.authorization.ChangePasswordPresenter;
import com.kma.summer2012.client.styles.style2.Recources;

public class ChangePasswordView extends Composite implements ChangePasswordPresenter.Display {
    interface ChangePasswordViewUiBinder extends UiBinder<Widget, ChangePasswordView> {
    }

    private static ChangePasswordViewUiBinder ourUiBinder = GWT.create(ChangePasswordViewUiBinder.class);

    @UiField
    protected Label errorLabel;

    @UiField
    protected TextBox passwordBox;

    @UiField
    protected TextBox passwordConfirmBox;

    @UiField
    protected Button saveButton;

    @UiField
    protected CheckBox showPassword;

    public ChangePasswordView() {
        HTMLPanel rootElement = (HTMLPanel) ourUiBinder.createAndBindUi(this);
        saveButton.addStyleName(Recources.INSTANCE.styles().Caption());
        initWidget(rootElement);

    }

    @Override
    public HasClickHandlers getSaveButton() {
        return this.saveButton;
    }

    @Override
    public String getPasswordTextBox() {
        return this.passwordBox.getValue();
    }

    @Override
    public String getPasswordConfirmTextBox() {
        return this.passwordConfirmBox.getValue();
    }

    @Override
    public void setPasswordTextBox(String text) {
        this.passwordBox.setValue(text);
    }

    @Override
    public void setPasswordConfirmTextBox(String text) {
        this.passwordConfirmBox.setValue(text);
    }

    @Override
    public CheckBox getShowPassword() {
        return this.showPassword;
    }

    @Override
    public void changePasswordTextBoxType() {
        if (this.passwordBox.getElement().getAttribute("type").equals("text")) {
            this.passwordBox.getElement().setAttribute("type", "password");
            this.passwordConfirmBox.getElement().setAttribute("type", "password");
        } else {
            this.passwordBox.getElement().setAttribute("type", "text");
            this.passwordConfirmBox.getElement().setAttribute("type", "text");
        }
    }

    @Override
    public void setErrorLabel(String text) {
        this.errorLabel.setText(text);
    }

    public Widget asWidget() {
        return this;
    }

}